package to52.android.database;

import java.util.GregorianCalendar;
import java.util.Random;

import fr.utbm.Patient;
import fr.utbm.PatientList;
import fr.utbm.Sensor;
import fr.utbm.Sensor.SensorType;
import fr.utbm.SensorValue;


public class DatabaseSimulator implements DatabaseModel {

	// singleton ; copy it in other db implementations
	private static DatabaseModel _this = null;
	public static DatabaseModel getInstance() {
		if ( _this == null ) {
			_this = new DatabaseSimulator();
		}
		return _this;
	}
	// ---
	

	private static PatientList patients = new PatientList();
	
	static {
		
		Patient david = new Patient("David LACHICHE");
		Patient xavier = new Patient("Xavier MICHEL");
		
		Sensor poidsSensor = new Sensor(SensorType.BALANCE);
		Sensor cardioSensor = new Sensor(SensorType.CARDIO);
		
		Random r = new Random();
		
		SensorValue[] l = new SensorValue[31];
		for (int i=0; i<31; ++i) {
			l[i] = new SensorValue(i,new GregorianCalendar(2011, 11, i), new Double(68 + r.nextInt(10)));
		}
		poidsSensor.add(l);
	
		SensorValue[] l2 = new SensorValue[31];
		for (int i=0; i<31; ++i) {
			l2[i] = new SensorValue(i,new GregorianCalendar(2011, 11, i), new Double(60 + r.nextInt(30)));
		}
		cardioSensor.add(l2);
		
		
		david.addSensor(poidsSensor);
		david.addSensor(cardioSensor);
		
		xavier.addSensor(poidsSensor);
		xavier.addSensor(cardioSensor);
		
        patients.addPatient(david);
        patients.addPatient(xavier);
	}



	@Override
	public PatientList getPatients() {
		return patients;
		
	}

	@Override
	public Patient getPatient(int id) {
		for (Patient p : patients.getPatients()) {
			if (p.getId() == id) {
				return p;
			}
		}
		return null;
	}

}
